#pragma once
#include<iostream>
#include<string>
#include<assert.h>
using namespace std;

template<class T>
class MyArray
{
public:
	MyArray() {};

	MyArray(int capacity);

	MyArray(const MyArray& array);

	~MyArray();

	void PushBack(const T& val);

	int getSize();

	int getCapacity();

	T& operator[](int index)
	{
		return this->pAddress[index];
	}

	MyArray& operator=(const MyArray& arr)
	{
		if (this->pAddress)
		{
			delete[] this->pAddress;
			this->pAddress = NULL;
		}

		this->m_Capacity = arr.m_Capacity;
		this->m_Size = arr.m_Size;
		this->pAddress = new T[this->m_Capacity];
		for (int i = 0; i < arr.m_Size; i++)
		{
			this->pAddress[i] = arr.pAddress[i];
		}
		return *this;
	}

private:
	T* pAddress;
	int m_Capacity;
	int m_Size;
};

template<class T>
MyArray<T>::MyArray(int capacity)
{
	this->m_Capacity = capacity;
	this->m_Size = 0;
	this->pAddress = new T[this->m_Capacity];

}

template<class T>
void MyArray< T>::PushBack(const T &val)
{
	assert(this->m_Capacity >= this->m_Size);
	this->pAddress[this->m_Size] = val;
	this->m_Size++;
}

template<class T>
int MyArray<T>::getSize()
{
	return this->m_Size;
}

template<class T>
int MyArray<T>::getCapacity()
{
	return this->m_Capacity;
}

template<class T>
MyArray<T>::~MyArray()
{
	if (this->pAddress)
	{
		delete [] this->pAddress;
		this->pAddress = NULL;
	}
	this->m_Capacity = 0;
	this->m_Size = 0;
}

template<class T>
MyArray<T>::MyArray(const MyArray & array)
{
	this->m_Capacity = array.m_Capacity;
	this->m_Size = array.m_Size;
	this->pAddress = new T[this->m_Capacity];
	for (int i = 0; i <array.m_Size; i++)
	{
		this->pAddress[i] = array.pAddress[i];
	}
}


